package com.example.common.utils.thread_local;

import com.example.common.pojo.ThreadLocalData;

/**
 * @Author zwp14
 * @create 2024/6/21 15:51
 * @description 当前线程变量工具
 */
public class CurrentThreadUtil {

    public static ThreadLocal<ThreadLocalData> threadLocal = new ThreadLocal<>();

    /**
     * 将数据存储到当前线程
     * @param data 要存储数据
     */
    public static void setThreadLocal(ThreadLocalData data) {
        threadLocal.set(data);
    }

    /**
     * @return 获得当前线程存储的数据
     */
    public static ThreadLocalData getThreadLocal() {
        return threadLocal.get();
    }

    /**
     * 清除线程存储的数据
     */
    public static void removeThreadLocalData() {
        threadLocal.remove();
    }
}
